﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Data;
using BusinessObjects.BO_GetObjects;
using DigiLib;

public partial class Administrator_Controls_Admin_Artlinks : Admin_Controls_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    //load data
    public void LoadData()
    {
        base.bindRepeater(rptData, BO_art_link.SelectWithPaged(base.Cur_page(pagerContainer), base.Page_size, 1), divMessage, pagerContainer);
    }
    protected void ddlAction_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            if (ddlAction.SelectedValue.Equals("0"))
                return;
            string selectedItems = GetSelectedItems(rptData, "chkBox");
            if (String.IsNullOrEmpty(selectedItems))
            {
                Javascripts.Alert(Page, "Phải chọn ít nhất 1 link!");
                return;
            }
            if (BO_art_link.Delete(selectedItems, ";", Convert.ToInt32(ddlAction.SelectedValue)))
            {
                divMessage.InnerHtml = MessageBox.Success("Thông Báo", "Thực hiện thành công.");
            }
            else
            {
                divMessage.InnerHtml = MessageBox.Error("Lỗi", "Chưa thực hiện được !");
            }
            LoadData();
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi hệ thống", "Phát hiện lỗi sau: " + ex.Message);
        }
    }
    protected void ddlModule_SelectedIndexChanged(object sender, EventArgs e)
    {
        LoadData();
    }
    public string GetSelectedItems(Repeater rpt, string chkBoxId)
    {
        var selectedValues = string.Empty;
        for (int i = 0; i < rpt.Items.Count; i++)
        {
            var chkBox = rpt.Items[i].FindControl(chkBoxId) as HtmlInputCheckBox;
            if (chkBox != null && chkBox.Checked)
                selectedValues += chkBox.Value + ";";
        }
        return selectedValues;
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {

    }
}